/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package IU;

import Logica.Carrera;
import Logica.Jugador;
import Logica.Participante;
import java.util.ArrayList;

/**
 *
 * @author jarzarello
 */
public class CarreraMonitor extends javax.swing.JDialog {

    private Carrera carrera;

    public Carrera getCarrera() {
        return carrera;
    }

    public void setCarrera(Carrera carrera) {
        this.carrera = carrera;
    }
    /**
     * Creates new form CarreraMonitor
     */
    public CarreraMonitor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        cargarDatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblInfo = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lblNumero = new javax.swing.JLabel();
        lblNombre = new javax.swing.JLabel();
        lblEstado = new javax.swing.JLabel();
        lblCantidadCaballos = new javax.swing.JLabel();
        lblMontoTotal = new javax.swing.JLabel();
        lblMontoPagado = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        lblCaballos = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstCaballosParticipantes = new javax.swing.JList();
        lblJugadores = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstJugadores = new javax.swing.JList();
        btnCerrar = new javax.swing.JButton();
        lblNumeroCarrera = new javax.swing.JLabel();
        lblNombreCarrera = new javax.swing.JLabel();
        lblEstadoCarrera = new javax.swing.JLabel();
        lblCaballosCarrera = new javax.swing.JLabel();
        lblMontoTotalJugado = new javax.swing.JLabel();
        lblMontoTotalPagado = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblInfo.setText("INFORMACION DE LA CARRERA");

        lblNumero.setText("N°:");

        lblNombre.setText("Nombre:");

        lblEstado.setText("Estado:");

        lblCantidadCaballos.setText("Cantidad de caballos:");

        lblMontoTotal.setText("Monto total jugado:");

        lblMontoPagado.setText("Monto Total pagado:");

        lblCaballos.setText("Lista de caballos participantes:");

        jScrollPane1.setViewportView(lstCaballosParticipantes);

        lblJugadores.setText("Lista de jugadores que ganaron:");

        jScrollPane2.setViewportView(lstJugadores);

        btnCerrar.setText("Cerrar");

        lblNumeroCarrera.setText("jLabel1");

        lblNombreCarrera.setText("jLabel1");

        lblEstadoCarrera.setText("jLabel1");

        lblCaballosCarrera.setText("jLabel1");

        lblMontoTotalJugado.setText("jLabel1");

        lblMontoTotalPagado.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1)
                    .addComponent(jSeparator2)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblInfo)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblNumero)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblNumeroCarrera))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblNombre)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblNombreCarrera))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblEstado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblEstadoCarrera))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblCantidadCaballos)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblCaballosCarrera))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblMontoTotal)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblMontoTotalJugado))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblMontoPagado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblMontoTotalPagado)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCaballos)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblJugadores)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnCerrar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblInfo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNumero)
                    .addComponent(lblNumeroCarrera))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(lblNombreCarrera))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEstado)
                    .addComponent(lblEstadoCarrera))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCantidadCaballos)
                    .addComponent(lblCaballosCarrera))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMontoTotal)
                    .addComponent(lblMontoTotalJugado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMontoPagado)
                    .addComponent(lblMontoTotalPagado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCaballos)
                    .addComponent(lblJugadores))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCerrar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCerrar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lblCaballos;
    private javax.swing.JLabel lblCaballosCarrera;
    private javax.swing.JLabel lblCantidadCaballos;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblEstadoCarrera;
    private javax.swing.JLabel lblInfo;
    private javax.swing.JLabel lblJugadores;
    private javax.swing.JLabel lblMontoPagado;
    private javax.swing.JLabel lblMontoTotal;
    private javax.swing.JLabel lblMontoTotalJugado;
    private javax.swing.JLabel lblMontoTotalPagado;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblNombreCarrera;
    private javax.swing.JLabel lblNumero;
    private javax.swing.JLabel lblNumeroCarrera;
    private javax.swing.JList lstCaballosParticipantes;
    private javax.swing.JList lstJugadores;
    // End of variables declaration//GEN-END:variables

    private void cargarDatos() {
        lblNumeroCarrera.setText(carrera.getNombre());
        lblNombreCarrera.setText(carrera.getNombre());
        lblEstadoCarrera.setText(carrera.getEstadoString());
        
        ArrayList<String> participantes = new ArrayList();
        for(Participante p:carrera.getParticipantes())
            participantes.add(formatearParticipante(p));
        
        lstCaballosParticipantes.setListData(participantes.toArray());
    }
    
    private String formatearParticipante (Participante p) {
        String ganador = "*GANADOR*";
        String participante = "N°: " + p.getNumero() + " - Nombre: " + p.getCaballo().getNombre() +
                " - Dividendo: " + p.getDividendo();;
        return participante;
    }
    
    private String formatearJugador (Jugador j) {
        return "N°: " + j.getNombreUsuario();
    }
}
